package com.jzo2o.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzo2o.health.model.domain.ReservationSetting;
import com.jzo2o.health.model.dto.request.ReservationSettingUpsertReqDTO;
import com.jzo2o.health.model.dto.response.ReservationSettingResDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author itcast
 * @since 2023-11-01
 */
public interface ReservationSettingMapper extends BaseMapper<ReservationSetting> {
    @Update("UPDATE reservation_setting SET reservations = reservations + 1 WHERE id = #{id} AND reservations < number")
    Integer updateReservations(@Param("id") Integer id);


    @Select("SELECT order_date date, number, reservations " +
            "FROM reservation_setting " +
            "WHERE order_date LIKE #{date} " +
            "ORDER BY order_date")
    List<ReservationSettingResDTO> getReservationSettingByMonth(@Param("date") String date);

    @Update("UPDATE reservation_setting\n" +
            "set number = #{number}\n" +
            "where order_date = #{date}")
    void editNumberByDate(@Param("date") String date, @Param("number") Integer number);

    @Insert("INSERT INTO reservation_setting (order_date, number) values (#{Date},#{number})")
    void upload(@Param("Date") String Date, @Param("number") Integer number);

    @Select("SELECT order_date date\n" +
            "    from reservation_setting\n" +
            "where order_date like #{month}\n" +
            "and number <> reservations")
    List<String> getReservationDateByMonth(@Param("month") String month);
}
